package com.zs.toolbox.web2j.system.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zs.toolbox.web2j.system.core.entity.WtDictionaryItemEntity;
import com.zs.toolbox.web2j.system.core.entity.WtDictionaryTypeEntity;
import com.zs.toolbox.web2j.system.core.mapper.other.WtDictionaryItemMapper;
import com.zs.toolbox.web2j.system.core.mapper.other.WtDictionaryTypeMapper;
import com.zs.toolbox.web2j.system.core.service.WtDictionaryTypeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.UUID;

/**
 * <p>
 * 字典类型表 服务实现类
 * </p>
 *
 * @author eric.zhang
 * @since 2018-10-08
 */
@Service
public class WtDictionaryTypeServiceImpl extends ServiceImpl<WtDictionaryTypeMapper, WtDictionaryTypeEntity> implements WtDictionaryTypeService {

    @Autowired
    WtDictionaryItemMapper wtDictionaryItemMapper;


    @Override
    public boolean saveOrUpdate(WtDictionaryTypeEntity entity) {
        if (StringUtils.isBlank(entity.getId())) {
            entity.setId(UUID.randomUUID().toString());
        }
        return super.saveOrUpdate(entity);
    }

    @Override
    @Transactional
    public boolean removeById(Serializable id) {
        wtDictionaryItemMapper.delete(new LambdaQueryWrapper<WtDictionaryItemEntity>().eq(
                WtDictionaryItemEntity::getTypeId, id
        ));
        this.baseMapper.deleteById(id);
        return  true;
    }
}
